//
//  GNVistorTableViewController.swift
//  SinaWeChat
//
//  Created by mac on 15/12/5.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class GNVistorTableViewController: UITableViewController {
    
    
    //用户是否登录
    var userLogin = GNUserAccountViewModel.sharedAccount.accessToken != nil
    
    //访客视图
    var vistorView :GNVistorView?
    
    
     // 在这个方法里面判断如果用户没有登录,就不执行 super.loadView, view 让我们自己来定义
    override func viewDidLoad() {
        super.viewDidLoad()

        
        
        userLogin ? super.loadView() : setupVisitorView()
    }

    
    //设置访客模式所要显示的的内容
    private func setupVisitorView(){
        
        
        vistorView = GNVistorView()
        
        vistorView?.registerButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        
        vistorView?.loginButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        
        view = vistorView
        
        //设置左边邮编登录注册
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target:self, action:"login")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "login")
        
        
    }
    
    @objc private func login(){
        
        print("login")
        
        //弹出一个登录的控制器
        
        let oauthVc = GNOAuthViewController()
        
       presentViewController(GNNavController(rootViewController:oauthVc), animated:true , completion: nil)
        
    }
    
    
    
    
    
}
